import numpy as np


# def cut(x):  # 将字符串沿着空格一分为二
#     leng = len(x)
#     answer0 = ''
#     answer1 = ''
#     n = 0
#     while n <= leng - 1:
#         if x[n] != ' ':
#             answer0+=x[n]
#             n += 1
#
#         elif x[n + 1] != ' ':
#             m = n + 1
#             while m <= leng - 1:
#                 answer1+=x[m]
#                 m += 1
#                 pass
#             break
#         else:
#             n += 1
#             pass
#         pass
#
#     return [answer0, answer1]
def cut(x):  # 将字符串沿着空格一分为二
    leng = len(x)
    ans = []

    n = 0
    temp = ''
    while n <= leng - 1:

        if x[n] != ' ':
            temp += x[n]
            if n==leng-1:
                ans.append(temp)


        elif x[n + 1] != ' ':
            ans.append(temp)
            temp = ''

        n += 1

    return ans


def loadDatadet(infile):
    with open(infile) as f:
        sourceInLine = f.readlines()
        dataset = []
        for line in sourceInLine:
            temp1 = line.strip('\n')
            temp2 = cut(temp1)
            list0 = []
            for item in temp2:
                item = float(item)
                list0.append(item)
                pass
            dataset.append(list0)
            pass

    return np.array(dataset)


if __name__ == '__main__':
    infile = '9v006.txt'
    infile = loadDatadet(infile)
    print(infile)
    # print(np.size(infile,axis=1))
    # print(cut("-2                        -0.08073428041187075"))
